package get.data;

import java.util.ArrayList;
import java.util.Scanner;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView;


/* The activity is passed a string with the index number 
 * of the node in nodes array, separated by space*/
 

public class NodeData extends Activity {
	
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.node_data);
	        
	        Intent data = getIntent ();
	        
			String s = data.getStringExtra("indexs");
        	Scanner lineScanner = new Scanner(s);
            lineScanner.useDelimiter(" ");
            
            while(lineScanner.hasNext()){
	            int pos = Integer.parseInt(lineScanner.next());
	    		System.out.println(pos+"");
	    		add_node_info(pos);
            }
            			
	 }

	private void add_node_info(int pos) {
		
    	LinearLayout layout = (LinearLayout) findViewById(R.id.nodelayer);
		TextView ip = new TextView(this);
		ip.setText(Main.nodes.get(pos).GetAdd());
		ip.setTextSize(20);
		ip.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);
		ip.setKeepScreenOn(true);
		layout.addView(ip);
		
		TextView status = new TextView(this);
		status.setText("Status: off");
    	layout.addView(status);

		
        if(Main.nodes.get(pos).GetStatus()==true){
        	status.setText("Status: on");
        	
        	TextView title1 = new TextView(this);
        	layout.addView(title1);
        	title1.setText("Parametres:");
        	
			if((Main.nodes).get(pos).GetLight()!=null){
	        	TextView power = new TextView(this);
	        	power.setText("Power "+NodeAdaptor.URLresponse(Main.nodes.get(pos).GetLight()).trim());
	        	layout.addView(power);
			}
			if((Main.nodes).get(pos).GetTemp()!=null){
	        	TextView temp = new TextView(this);
	        	temp.setText("Temperature "+NodeAdaptor.URLresponse(Main.nodes.get(pos).GetTemp()).trim());
	        	layout.addView(temp);
			}
			
        	TextView title2 = new TextView(this);
        	layout.addView(title2);
        	title2.setText("Actions:");
        	
        	TextView change_status = new TextView(this);
        	layout.addView(change_status);
        	
        }
	}
}
